package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface OrderMapper {


    void insert(Orders orders);


    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);
    //根据ID查询订单
@Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

@Select("select count(id) from orders where status=#{status}")
    Integer countOrders(Integer status);

    /**
     * 根据订单id查询订单状态
     * @param orders
     * @return
     */
    @Select("select status from orders where id = #{id}")
    Integer getStatus(Orders orders);

@Insert("insert into orders(rejection_reason) values (#{rejectionReason})")
    void insertRejectionReason(Orders orders);

    /**
     * 根据订单状态和下单时间查询订单
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
List<Orders> getBystatusAndOrderTimeLt(Integer status, LocalDateTime orderTime);
/*
统计营销额
 */
    Double sumByMap(HashMap<Object, Object> map);

    /**
     * 统计指定时间内的销量排名前10
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin,LocalDateTime end);

    Integer countByMap(HashMap<Object, Object> map);
}
